import 'package:Smart/pages/center_page.dart';
import 'package:Smart/pages/home_page.dart';
import 'package:Smart/pages/mine_page.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  int _currentIndex = 1;
  final PageController _controller = PageController(initialPage: 1);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        pageSnapping: false,
        controller: _controller,
        scrollDirection: Axis.horizontal,
        physics: NeverScrollableScrollPhysics(),
        children: [Home(), CenterPage(), Mine()],
      ),
      bottomNavigationBar: ConvexAppBar(
        height: 56,
        backgroundColor: Colors.white,
        activeColor: Color(0xFF141413),
        color: Color(0xFF141413),
        curveSize: 80,
        curve: Curves.bounceInOut,
        initialActiveIndex: _currentIndex,
        items: [
          TabItem(
            title: '安排计划',
            icon: Image.asset("assets/images/icon_10.png"),
            activeIcon:
                Image.asset("assets/images/icon_11.png"),
          ),
          TabItem(
            title: '学习练习',
            icon: Image.asset("assets/images/icon_20.png"),
            activeIcon: Image.asset("assets/images/icon_21.png"),
          ),
          TabItem(
            title: '项目工作',
            icon: Image.asset("assets/images/icon_30.png"),
            activeIcon: Image.asset("assets/images/icon_31.png"),
          ),
        ],
        onTabNotify: (index) {
          return true;
        },
        onTap: (index) {
          print("点击了Tabbar index $index");
          setState(() {
            _currentIndex = index;
          });
          _controller.jumpToPage(index);
        },
        style: TabStyle.react,
      ),
    );
  }
}
